Private Sub txtOnlyLetters_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtOnlyLetters.KeyPress
 
        ' Accetto solo l'immissione di lettere
 
        Dim KeyAscii As Short = Asc(e.KeyChar)
 
        ' Le lettere maiuscole hanno i codici ascii tra
        ' 65 e 90, quelle minuscole tra 97 e 122.
        ' Devo comunque fare in modo che l'utente
        ' sia in grado di digitare anche il tasto BackSpace
        ' (ascii=8) e il tasto Canc (ascii=24)
        If KeyAscii < 65 And KeyAscii <> 24 And KeyAscii <> 8 Then
            KeyAscii = 0
        ElseIf KeyAscii > 90 And KeyAscii < 97 Then
            KeyAscii = 0
        ElseIf KeyAscii > 122 Then
            KeyAscii = 0
        End If
 
        ' Reimposto il KeyChar
        e.KeyChar = Chr(KeyAscii)
    End Sub